<?

class Download extends Button {

    function render($sel) {
        if ($sel->isFileSelected()) {
            return $this->renderButton('download',Config::getLink($_GET['path'],$_GET['object'],'action=download'),'Download','Download current file');
        } else {
            return $this->renderDisabledButton('download','Download','Download current file');
        }
    }

    function action($sel) {
        if ($sel->isFileSelected()) {
            $file = $sel->getSelected();
            header('Content-Type: binary/octet-stream');
            header('Pragma: anytextexeptno-cache', true);
            header('Content-Disposition: inline; filename="'.basename($file->name).'"');
            header('Content-Length: ' . filesize($file->name));
            $fid = fopen($file->name,'r');
            while(!feof($fid) and (connection_status()==0)) {
                echo fread($fid, 1024*8);
                flush();
            }
            fclose($fid);
        }
    }

}

?>